import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'
import Login from '../views/login/index'

import i18n from '@/lang'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  // { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  {
    path: '/login',
    component: Login,
    redirect: '/login/login',
    hidden: true,
    children: [
      {
        path: 'login',
        component: () => import('@/views/login/loginForm/index') // Parent router-view
      }, {
        path: 'register',
        component: () => import('@/views/login/registerForm/index')
      }, {
        path: 'forgotPassword',
        component: () => import('@/views/login/forgotPasswordForm/index')
      }
    ]
  },
  { path: '/404', component: () => import('@/views/404'), hidden: true },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'Dashboard',
    hidden: true,
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index')
    }]
  }
]

export const asyncRouterMap = [
  {
    path: '/production',
    component: Layout,
    redirect: '/production/management',
    name: i18n.t('production.productionManagement'),
    meta: { title: i18n.t('production.productionManagement'), icon: 'home' },
    children: [
      {
        path: 'management',
        name: i18n.t('production.productionManagement'),
        component: () => import('@/views/productionManagement/index'),
        meta: { title: i18n.t('production.productionManagement'), icon: 'table' }
      },
      {
        path: 'addProduct',
        name: i18n.t('production.addProduction'),
        component: () => import('@/views/productionManagement/productionEdit/index'),
        meta: { title: i18n.t('production.addProduction'), icon: 'table' },
        hidden: true
      },
      {
        path: 'editProduct',
        name: i18n.t('production.editProduct'),
        component: () => import('@/views/productionManagement/productionEdit/index'),
        meta: { title: i18n.t('production.editProduct'), icon: 'table' },
        hidden: true
      },
      {
        path: 'editProductResult',
        name: i18n.t('production.editProductResult'),
        component: () => import('@/views/productionManagement/createProductResult/index'),
        meta: { title: i18n.t('production.editProductResult'), icon: 'table' },
        hidden: true
      },
      {
        path: 'productDetail',
        name: i18n.t('production.productDetail'),
        component: () => import('@/views/productionManagement/productDetail/index'),
        meta: { title: i18n.t('production.productDetail'), icon: 'table' },
        hidden: true
      }
    ]
  }, {
    path: '/user',
    component: Layout,
    redirect: '/user/management',
    name: i18n.t('user.userManagement'),
    meta: { title: i18n.t('user.userManagement'), icon: 'user' },
    children: [{
      path: 'management',
      name: i18n.t('user.user'),
      component: () => import('@/views/userManagement/index'),
      meta: { title: i18n.t('user.user') }
    }, {
      path: 'addUser',
      name: i18n.t('user.addUser'),
      component: () => import('@/views/userManagement/userEdit'),
      meta: { title: i18n.t('user.addUser') },
      hidden: true
    }, {
      path: 'editUser',
      name: i18n.t('user.editUser'),
      component: () => import('@/views/userManagement/userEdit'),
      meta: { title: i18n.t('user.editUser') },
      hidden: true
    }, {
      path: 'detail',
      name: i18n.t('user.detail'),
      component: () => import('@/views/userManagement/userDetail'),
      meta: { title: i18n.t('user.detail') },
      hidden: true
    }]
  }, {
    path: '/role',
    component: Layout,
    redirect: '/role/management',
    name: i18n.t('role.management'),
    meta: { title: i18n.t('role.management'), icon: 'role' },
    children: [{
      path: 'management',
      name: i18n.t('role.role'),
      component: () => import('@/views/roleManagement/index'),
      meta: { title: i18n.t('role.role') }
    }, {
      path: 'addRole',
      component: () => import('@/views/roleManagement/roleEdit'),
      name: i18n.t('role.addRole'),
      meta: { title: i18n.t('role.addRole') },
      hidden: true
    }, {
      path: 'editRole',
      component: () => import('@/views/roleManagement/roleEdit'),
      name: i18n.t('role.editRole'),
      meta: { title: i18n.t('role.editRole') },
      hidden: true
    }, {
      path: 'detail',
      component: () => import('@/views/roleManagement/roleDetail'),
      name: i18n.t('role.roleDetail'),
      meta: { title: i18n.t('role.roleDetail') },
      hidden: true
    }]
  }, {
    path: '/permission',
    component: Layout,
    redirect: '/permission/management',
    name: i18n.t('user.permissionManagement'),
    meta: { title: i18n.t('user.permissionManagement'), icon: 'permission' },
    children: [{
      path: 'management',
      name: i18n.t('user.permissionManagement'),
      component: () => import('@/views/permissionManagement/index'),
      meta: { title: i18n.t('user.permissionManagement') }
    }, {
      path: 'addPermission',
      component: () => import('@/views/permissionManagement/permissionEdit'),
      name: i18n.t('user.addPermission'),
      meta: { title: i18n.t('user.addPermission') },
      hidden: true
    }, {
      path: 'editPermission',
      component: () => import('@/views/permissionManagement/permissionEdit'),
      name: i18n.t('permission.editPermission'),
      meta: { title: i18n.t('permission.editPermission') },
      hidden: true
    }, {
      path: 'detail',
      component: () => import('@/views/permissionManagement/permissionDetail'),
      name: i18n.t('permission.detail'),
      meta: { title: i18n.t('permission.detail') },
      hidden: true
    }]
  },
  {
    path: '/form',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/index'),
        meta: { title: 'Form', icon: 'form' }
      }
    ]
  },

  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: {
      title: 'nested',
      icon: 'nested'
    },
    children: [
      {
        path: 'menu1',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'Menu1',
        meta: { title: 'menu1' },
        children: [
          {
            path: 'menu1-1',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'Menu1-1',
            meta: { title: 'menu1-1' }
          },
          {
            path: 'menu1-2',
            component: () => import('@/views/nested/menu1/menu1-2'),
            name: 'Menu1-2',
            meta: { title: 'menu1-2' },
            children: [
              {
                path: 'menu1-2-1',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
                name: 'Menu1-2-1',
                meta: { title: 'menu1-2-1' }
              },
              {
                path: 'menu1-2-2',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
                name: 'Menu1-2-2',
                meta: { title: 'menu1-2-2' }
              }
            ]
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/nested/menu1/menu1-3'),
            name: 'Menu1-3',
            meta: { title: 'menu1-3' }
          }
        ]
      },
      {
        path: 'menu2',
        component: () => import('@/views/nested/menu2/index'),
        meta: { title: 'menu2' }
      }
    ]
  },

  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: { title: 'externalLink', icon: 'link' }
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
